package codingforgreat.lchot150;

public class Lc198 {
    //超时
    public int rob(int[] nums) {
        return  process(nums,0,0);
    }
    public int process(int[] nums,int index,int path){
        if(index >= nums.length){
            return path;
        }
        return Math.max(process(nums,index + 2,path + nums[index]),process(nums,index + 1,path));
    }
    public int rob1(int[] nums) {
        int N = nums.length;
        int[] dp = new int[N + 2];
        dp[N] = 0;dp[N +1] = 0;
        for(int i = N - 1;i >= 0;i--){
            dp[i] = Math.max(dp[i + 2] + nums[i],dp[i + 1]);
        }
        return dp[0];
    }
    public int process(int[] nums,int index){
        if(index >= nums.length){
            return 0;
        }
        return Math.max(process(nums,index + 2)+ nums[index],process(nums,index + 1));
    }
}
